package com.lh.controller;

import com.lh.Service.UserService;
import com.lh.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/user")

public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("/login")
    public String login(String user_name, String user_password, HttpServletRequest request){
        User user = userService.login(user_name, user_password);
        if (user == null){
            request.setAttribute("tips","账号或密码错误");
            return "/html/login";
        }else {
            request.getSession().setAttribute("user",user);
            return "redirect:/html/price.jsp";
        }

    }

    @RequestMapping("/register")
    public String  register(String user_name,String user_password,String user_salt){
        User user = new User(null,user_name,user_password,user_salt);
        boolean b = userService.register(user);
        String path = b?"/login.jsp":"/register.jsp";
        return path;
    }


}
